package lib

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"log"
)

var Gorm *gorm.DB

func init() {

	Gorm = GormDB()

}

func GormDB() *gorm.DB {

	dsn := "root:root@tcp(192.168.56.102:3306)/test?charset=utf8mb4"

	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})

	if err != nil {
		log.Fatal(err)
	}

	mysql, err := db.DB()
	if err != nil {
		log.Println(err)
	}

	mysql.SetMaxIdleConns(5)
	mysql.SetMaxOpenConns(10)

	return db

}
